package com.xjgz.aio.socket.transport;

import com.xjgz.aio.socket.MessageProcessor;
import com.xjgz.aio.socket.NetMonitor;
import com.xjgz.aio.socket.Protocol;

import java.net.SocketOption;
import java.util.HashMap;
import java.util.Map;

final class IoServerConfig {

    public static final String BANNER = "\n" +
        "                               _                           _             _   \n" +
        "                              ( )_                        ( )           ( )_ \n" +
        "  ___   ___ ___     _ _  _ __ | ,_)     ___    _      ___ | |/')    __  | ,_)\n" +
        "/',__)/' _ ` _ `\\ /'_` )( '__)| |     /',__) /'_`\\  /'___)| , <   /'__`\\| |  \n" +
        "\\__, \\| ( ) ( ) |( (_| || |   | |_    \\__, \\( (_) )( (___ | |\\`\\ (  ___/| |_ \n" +
        "(____/(_) (_) (_)`\\__,_)(_)   `\\__)   (____/`\\___/'`\\____)(_) (_)`\\____)`\\__)";

    public static final String VERSION = "0.0.1";

    private int readBufferSize = 512;

    private int writeChunkSize = 128;

    private int writeChunkCount = 16;

    private String host;

    private NetMonitor monitor;

    private int port = 8888;

    private int backlog = 1000;

    @SuppressWarnings("rawtypes")
    private MessageProcessor processor;

    @SuppressWarnings("rawtypes")
    private Protocol protocol;

    private boolean bannerEnabled = true;

    private Map<SocketOption<Object>, Object> socketOption;

    private int threadNum = 1;

    public int getWriteChunkSize() {
        return writeChunkSize;
    }

    public void setWriteChunkSize(int writeChunkSize) {
        this.writeChunkSize = writeChunkSize;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getReadBufferSize() {
        return readBufferSize;
    }

    public void setReadBufferSize(int readBufferSize) {
        this.readBufferSize = readBufferSize;
    }

    public int getWriteChunkCount() {
        return writeChunkCount;
    }

    public void setWriteChunkCount(int writeChunkCount) {
        this.writeChunkCount = writeChunkCount;
    }

    public NetMonitor getMonitor() {
        return monitor;
    }

    public void setMonitor(NetMonitor monitor) {
        this.monitor = monitor;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public int getBacklog() {
        return backlog;
    }

    public void setBacklog(int backlog) {
        this.backlog = backlog;
    }

    @SuppressWarnings("rawtypes")
    public MessageProcessor getProcessor() {
        return processor;
    }

    public void setProcessor(@SuppressWarnings("rawtypes") MessageProcessor processor) {
        this.processor = processor;
    }

    @SuppressWarnings("rawtypes")
    public Protocol getProtocol() {
        return protocol;
    }

    public void setProtocol(@SuppressWarnings("rawtypes") Protocol protocol) {
        this.protocol = protocol;
    }

    public boolean isBannerEnabled() {
        return bannerEnabled;
    }

    public void setBannerEnabled(boolean bannerEnabled) {
        this.bannerEnabled = bannerEnabled;
    }

    public Map<SocketOption<Object>, Object> getSocketOption() {
        return socketOption;
    }

    public void setSocketOption(SocketOption<Object> socketOption, Object v) {
        if (socketOption == null) {
            this.socketOption = new HashMap<>(4);
        }
        this.socketOption.put(socketOption, v);
    }

    public int getThreadNum() {
        return threadNum;
    }

    public void setThreadNum(int threadNum) {
        this.threadNum = threadNum;
    }

    @Override
    public String toString() {
        return "IoServerConfig{" +
            "readBufferSize=" + readBufferSize +
                ", writeBufferSize=" + writeChunkSize +
                ", writeBufferCapacity=" + writeChunkCount +
            ", host=" + host +
            ", monitor=" + monitor +
            ", port=" + port +
            ", backlog=" + backlog +
            ", processor=" + processor +
            ", protocol=" + protocol +
            ", bannerEnabled=" + bannerEnabled +
            ", socketOption=" + socketOption +
            ", threadNum=" + threadNum +
            "}";
    }
}
